{extend name="sitehome@style/base"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-form config-form">
    <div class="nc-quote-box ">
    	<blockquote class="layui-elem-quote layui-quote-nm">小程序开发者设置</blockquote>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序名称</label>
            <div class="layui-input-inline medium">
                <input type="text" name="weapp_name" autocomplete="off" placeholder="公众号名称" class="layui-input" {notempty name="$config_info"}value="{$config_info.weapp_name}"{/notempty}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序账号</label>
            <div class="layui-input-inline medium">
                <input type="text" name="weapp_account" autocomplete="off" placeholder="小程序账号" class="layui-input" {notempty name="$config_info"}value="{$config_info.weapp_account}"{/notempty}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label img-upload-lable">小程序二维码</label>
            <div class="layui-inline img-upload">
                <input type="hidden" class="layui-input" name = "weapp_code" {notempty name="$config_info"}value="{$config_info.weapp_code}"{/notempty} />
                <div class="upload-img-block weapp-code">
                    {if empty($config_info.weapp_code)}
                    <div class="upload-img-box" onclick="uploadSingleweapp_code()">
                        <div>
                            <i class="add">+</i>
                        </div>
                    </div>
                    {else/}
                    <div class="upload-img-box has-choose-image">
                        <div>
                            <img src="{:img($config_info.weapp_code)}" layer-src="{:img($config_info.weapp_code)}">
                        </div>
                        <span onclick="uploadSingleweapp_code();">修改</span>
                    </div>
                    {/if}
                </div>
                {:hook("fileUpload", ['name' => 'weapp_code', 'type' => 'common', 'file_type' => 'IMAGE', 'size' => '2000'], '', true)}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小程序原始ID</label>
            <div class="layui-input-inline medium">
                <input type="text" name="weapp_original" autocomplete="off" placeholder="小程序原始ID" class="layui-input" {notempty name="$config_info"}value="{$config_info.weapp_original}"{/notempty}>
            </div>
        </div>
    </div>
    <div class="nc-quote-box ">
        <blockquote class="layui-elem-quote layui-quote-nm">开发者ID设置</blockquote>
        <div class="layui-card-body">
            <div class="layui-form-item">
            <label class="layui-form-label">APPID</label>
                <div class="layui-input-block">
                    <input type="text" name="appid" autocomplete="off" placeholder="AppID" class="layui-input nc-len-long" {notempty name="$config_info"}value="{$config_info.appid}"{/notempty}>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">APP密钥</label>
                <div class="layui-input-block">
                    <input type="text" name="appsecret" autocomplete="off" placeholder="Appsecret" class="layui-input nc-len-long" {notempty name="$config_info"}value="{$config_info.appsecret}"{/notempty}>
                </div>
                <div class="layui-form-mid layui-word-aux">AppID(小程序ID)和AppSecret(小程序密钥)来自于您申请的小程序账号，使用小程序账号密码登录公众平台，在开发->开发设置中可以找到</div>
            </div>
        </div>
    </div>
    <div class="nc-quote-box ">
        <blockquote class="layui-elem-quote layui-quote-nm">服务器配置信息</blockquote>
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label">request合法域名</label>
                <div class="layui-input-inline nc-len-long">
                    <input  class="layui-input"type="text" name=""id="request_domain" autocomplete="off" placeholder="request合法域名" value="{$url}" readonly>
                </div>
                <button class="layui-btn layui-btn-primary" onclick="nc.copy('request_domain')">复制</button>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">socket合法域名</label>
                <div class="layui-input-inline nc-len-long">
                    <input type="text"  autocomplete="off" placeholder="socket合法域名" id="socket_domain" class="layui-input" value="{$url}" readonly>
                </div>
                <button class="layui-btn layui-btn-primary" onclick="nc.copy('socket_domain')">复制</button>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">uploadFile合法域名</label>
                <div class="layui-input-inline nc-len-long">
                    <input type="text" autocomplete="off" placeholder="uploadFile合法域名" id="uploadFile_domain" class="layui-input" value="{$url}" readonly>
                </div>
                <button class="layui-btn layui-btn-primary" onclick="nc.copy('uploadFile_domain')">复制</button>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">downloadFile合法域</label>
                <div class="layui-input-inline nc-len-long">
                    <input type="text" autocomplete="off" placeholder="downloadFile合法域" id="downloadFile_domain" class="layui-input" value="{$url}" readonly>
                </div>
                <button class="layui-btn layui-btn-primary" onclick="nc.copy('downloadFile_domain')">复制</button>
            </div>
        </div>
    </div>
    <div class="nc-quote-box ">
        <blockquote class="layui-elem-quote layui-quote-nm">消息推送设置</blockquote>
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label">URL(服务器地址)</label>
                <div class="layui-input-inline nc-len-long">
                    <input  class="layui-input"type="text"  autocomplete="off" id="callback_url"  placeholder="request合法域名" value="{$url}" readonly>
                </div>
                <button class="layui-btn layui-btn-primary" onclick="nc.copy('callback_url')">复制</button>
                <div class="layui-form-mid layui-word-aux">必须以http://或https://开头，分别支持80端口和443端口。</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Token(令牌)</label>
                <div class="layui-input-inline nc-len-long">
                    <input  class="layui-input"type="text" name="token" id="token" autocomplete="off" placeholder="请填写微信小程序消息推送校验Token" {notempty name="$config_info"}value="{$config_info.token}"{/notempty}>
                </div>
                <button class="layui-btn layui-btn-primary" onclick="nc.copy('token')">复制</button>
                <div class="layui-form-mid layui-word-aux">Token必须为英文或数字，长度为3-32字符。如不填写则默认为“TOKEN”。</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">EncodingAESKey(消息加解密密钥)</label>
                <div class="layui-input-inline nc-len-long">
                    <input  class="layui-input"type="text" name="encodingaeskey" id="encodingaeskey" autocomplete="off" placeholder="请填写微信小程序消息加解密密钥" {notempty name="$config_info"}value="{$config_info.encodingaeskey}"{/notempty}>
                </div>
                <button class="layui-btn layui-btn-primary  " onclick="nc.copy('encodingaeskey')">复制</button>
                <div class="layui-form-mid layui-word-aux">消息加密密钥由43位字符组成，字符范围为A-Z,a-z,0-9</div>
            </div>
            <div class="nc-form-row">
                <button class="layui-btn" lay-submit lay-filter="formSave">保存</button>
                <button class="layui-btn layui-btn-primary" onclick="javascript:history.go(-1);">返回</button>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
layui.use(['form'], function() {
	var form = layui.form;
	var repeat_flag = false;//防重复标识
	form.on('submit(formSave)', function (data) {
		if (repeat_flag) return;
		repeat_flag = true;
		$.ajax({
			type: "post",
			url: "{:addon_url('WeApp://sitehome/config/config')}",
			dataType: "JSON",
			data: data.field,
			success: function (data) {
				repeat_flag = false;
				layer.msg(data.message);
			}
		});
	});
	
});

/**
 * 单图回调事件
 */
function singleImageUploadSuccess(res,name){
    if(name == "weapp_code"){
        $(".weapp-code").html('<div class="upload-img-box has-choose-image"><div><img src="'+nc.img(res.path)+'" layer-src="'+nc.img(res.path)+'"></div><span onclick="uploadSingleweapp_code();">修改</span></div>');
        $("input[name='weapp_code']").val(res.path);
    }
}
</script>
{/block}